package com.sh.data.engine.repository.dao.integration.api.webservice.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
import com.sh.data.engine.repository.dao.base.EngineBaseModel;
import com.sh.data.engine.repository.dao.integration.api.http.entity.ApiResponseEntity;
import com.sh.data.engine.repository.dao.integration.api.http.entity.TaskConfigParamEntity;
import lombok.*;

import java.util.Date;
import java.util.List;

/**
 * @author : changkong
 * @date : 2022/1/17
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName(value = "tb_api_webservice", autoResultMap = true)
@EqualsAndHashCode(callSuper = true)
public class ApiWsEntity extends EngineBaseModel<ApiWsEntity> {

    private Long projectId;

    /**
     * xxl任务id
     */
    private Integer xxlJobId;

    // 任务名称
    private String taskName;

    // 请求配置
    @TableField(typeHandler = FastjsonTypeHandler.class)
    private ApiWsRequest apiWsRequest;

    // 返回值
    @TableField(typeHandler = FastjsonTypeHandler.class)
    private ApiResponseEntity apiResponse;

    // 目标数据源, 字段, 生效时间等配置
    @TableField(typeHandler = FastjsonTypeHandler.class)
    private TaskConfigParamEntity taskConfigParam;

    // datax任务脚本
    private String dataxJobScript;

    // 任务运行状态
    private Integer taskStatus;

    // update by xxl
    private Date startTime;

    // update by xxl
    private Date endTime;

    // 任务删除状态
    private Integer rowState;

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class ApiWsRequest {
        //  jax-ws jax-rs
        private String protocol;

        // wsdl address
        private String address;

        // 解析wsdl地址需要的用户名
        private String addressUserNameKey;

        private String addressUserNameValue;

        // 解析wsdl地址需要的密码
        private String addressPasswordKey;

        private String addressPasswordValue;

        // wsdl解析的class文件地址
        private String localClassPath;

        // ws service
        private String service;

        // ws port
        private String port;

        // ws operation
        private String operation;

        // 认证参数
        private ApiHttpAuthParam apiWsAuthParam;

        // 请求头
        //    private ApiHttpRequestHeaderParam apiHttpRequestHeaderParam;

        // 请求体
        private ApiHttpRequestBodyParam apiWsRequestBodyParam;
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class ApiHttpAuthParam {
        // 认证方式    noauth, basic, sign, token
        private String authType;

        // basic
        private String authUsername;
        private String authPassword;

        // sign
        private String accessKey;
        private String accessSecret;

        // token
        private String accessToken;

        private String advancedCacheKey;
        // jar包名
        private String advancedFileName;
        // 资源路径
        private String advancedFilePath;

        private String advanceClassReference;

        private String advanceMethodName;

        // 变量有效期
        private Date expires;
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class ApiHttpRequestHeaderParam {
        // 请求头列表
        private List<Header> params;

        @Data
        @NoArgsConstructor
        @AllArgsConstructor
        public static class Header {
            // 消息头名称
            private String name;
            // 具体值
            private String value;
        }
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class ApiHttpRequestBodyParam {
        private String contentType;
        // 请求体
        private String body;

        // url参数
        private List<FormParam> formParams;

        @Data
        @NoArgsConstructor
        @AllArgsConstructor
        public static class FormParam {

            /**
             * 参数类型 0-输入参数 1-返回参数
             */
            private Integer paramType;

            /**
             * 参数名称
             */
            private String paramName;

            /**
             * 参数位置 query head body
             */
            private String paramPosition;

            /**
             * 参数数据类型
             */
            private String paramDataType;

            /**
             * 参数值
             */
            private String paramValue;

            /**
             * 描述
             */
            private String paramDesc;

            /**
             * 返回参数取值表达式
             */
            private String paramExpression;

            /**
             * 参数属性 0-无(纯输入值) 1-pageNo 2-pageSize
             */
            private Integer paramAttribute;
        }
    }
}
